import 'dart:ui';

import 'package:flutter/material.dart';

import 'base/base_effect.dart';
import 'effect_template.dart';

class Effect14 extends EditableAnimationEffect {
  @override
  List<Color> get defaultColors {
    return const [
      Color(0xFFFF0000),
      Color(0xFFFFFFFF)
    ];
  }

  @override
  bool get enableAngle => true;

  @override
  RangeArgument get angleRange => RangeArgument(-180, 180, 0);

  @override
  bool get enableColorWidth => true;

  @override
  RangeArgument get colorWidthRange => RangeArgument(1, 16, 4);

  @override
  bool get enableDensity => false;

  @override
  bool get enableEditColor => true;

  @override
  bool get enableSpeed => false;

  @override
  bool get isFixedColorCount => false;

  @override
  RangeArgument get colorCountRange => RangeArgument(1,6,3);

  @override
  EffectType get effectTyp => EffectType.effect14;

  @override
  Future<List<List<List<Color>>>> getFrames({EffectOperation? operation}) {
    List<Color> colorList = getColorList(effectOperation: operation);
    int angle = getAngle(effectOperation: operation); //弧度
    Size rotateSize = getRotateSize(angle: angle);
    double newWidth = rotateSize.width;
    double newHeight = rotateSize.height;

    List<List<List<Color>>> frames = [];
    int colorWidth = operation?.colorWidth ?? colorWidthRange.defaultValue;
    int totalFrame = (colorWidth * 2) * colorList.length;
    for (int i = 0; i < totalFrame; i++) {
      List<List<Color>> singleFrame = [];
      for (int j = 0; j < newWidth; j++) {
        List<Color> columns = [];
        for (int z = 0; z < newHeight; z++) {
          int realWidth = colorWidth * 2;
          int realIndex = z +  i + j;
          int currentIndex = (realIndex ~/ realWidth) % colorList.length;
          if (realIndex % realWidth >= colorWidth) {
            columns.add(Colors.black);
            // columns.add(Colors.black);
          } else {
            columns.add(colorList[currentIndex]);
          }
        }
        singleFrame.add(columns);
      }
      frames.add(singleFrame);
    }
    return Future.value(frames);
  }

  @override
  Size get size => const Size(24, 24);
}